﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SARUserControls
{
	/// <summary>
	/// 复选框
	/// </summary>
	public partial class SARCheckBox : UserControl
	{
		public SARCheckBox()
		{
			this.InitializeComponent();            
		}

        /// <summary>
        /// 复选框对应的文本
        /// </summary>
        public string SARText
        {
            set
            {
                this.txtLabel.Text = value;
            }
            get
            {
                return this.txtLabel.Text;
            }
        }

        /// <summary>
        /// 复选框被选择的事件
        /// </summary>
        public event RoutedEventHandler SARChecked;

        /// <summary>
        /// 复选框被单击的事件
        /// </summary>
        public event RoutedEventHandler SARClick;

        private bool? isChecked;

        /// <summary>
        /// 复选框是否被选中
        /// </summary>
        public bool? SARIsChecked
        {
            get
            {
                isChecked = this.chechBox.IsChecked;
                return isChecked;
            }
            set
            {
                isChecked = value;
                this.chechBox.IsChecked = value;
            }
        }

        private void chechBox_Checked(object sender, RoutedEventArgs e)
        {
            if (SARChecked != null)
            {
                SARChecked.Invoke(this, e);
            }
        }

        private void chechBox_Click(object sender, RoutedEventArgs e)
        {
            if (SARClick != null)
            {
                SARClick.Invoke(this, e);
            }
        }        
	}
}